@extends('admin.layouts.app')

@section('right-content')

    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>新增广播</legend>
    </fieldset>

    <form class="layui-form" action="" style="margin-right: 60%">
        <div class="layui-form-item">
            <label class="layui-form-label">开始时间</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" name="start_time" id="start_time" placeholder="请输入开始时间" readonly="">
            </div>
            <div class="layui-form-mid layui-word-aux"></div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">持续时间</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" lay-verify="required" name="last_time" id="last_time" placeholder="请输入持续时间">
            </div>
            <div class="layui-form-mid layui-word-aux">以小时为单位, 不足一小时用小数表示</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">广播次数</label>
            <div class="layui-input-inline">
                <input type="text" name="repeat_times" value="0" lay-verify="required|number" autocomplete="off" placeholder="请输入广播次数" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">0不限制次数</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">广播间隔</label>
            <div class="layui-input-block">
                <select name="interval_time" >
                    <option value="0">无限制</option>
                    <option value="1">1</option>
                    <option value="2">2</option>
                    <option value="3">3</option>
                    <option value="4">4</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">广播内容</label>
            <div class="layui-input-block">
                <textarea placeholder="请输入内容" lay-verify="required" class="layui-textarea" name="content"></textarea>
            </div>
        </div>

        <div class="layui-form-item" >
            <label class="layui-form-label">状态</label>
            <div class="layui-input-block">
                <input type="radio" name="enable" value="1" title="上线" checked>
                <input type="radio" name="enable" value="0" title="下线">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="button" class="layui-btn" lay-submit="" lay-filter="sub" data-url="{{ route('broadcasts.store') }}">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
@endsection

@section('my-js')
<script type="text/javascript">
Date.prototype.format = function(fmt) {
     var o = {
        "M+" : this.getMonth()+1,                 //月份
        "d+" : this.getDate(),                    //日
        "h+" : this.getHours(),                   //小时
        "m+" : this.getMinutes(),                 //分
        "s+" : this.getSeconds(),                 //秒
        "q+" : Math.floor((this.getMonth()+3)/3), //季度
        "S"  : this.getMilliseconds()             //毫秒
    };
    if(/(y+)/.test(fmt)) {
            fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
    }
     for(var k in o) {
        if(new RegExp("("+ k +")").test(fmt)){
             fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
         }
     }
    return fmt;
}

   layui.use(['form', 'laydate'], function(){
       var form = layui.form, laydate = layui.laydate;

        laydate.render({
            elem: '#start_time', //指定元素
            type: 'time',
            format: 'HH:mm:ss',
            // value: laydate.now(),
        });


        form.on('submit(sub)', function(data){
            var url = $(this).attr('data-url');
            commonAjaxSubmit(url, 'POST');
        })
    });
</script>
@endsection

